﻿@model IEnumerable<ESupervision.Models.MessageSent>

@{
    ViewBag.Title = "Messaging - Sent";
}


<h2>Messaging - Sent</h2>


<div class="row">
    <div class="col-md-2">
        <p>
            <button type="button" class="btn btn-warning" onclick="location.href='@Url.Action("Compose")'">Compose</button>

        </p>
        <ul class="nav nav-pills nav-stacked">
            <li role="presentation"><a href="@Url.Action("Index")">Inbox</a></li>
            <li role="presentation" class="active"><a href="@Url.Action("Sent")">Sent</a></li>
        </ul>

    </div>
    @using (Html.BeginForm("DoAction", "Message"))
    {
        @Html.AntiForgeryToken()
        <div class="col-md-10">
            <div class="btn-group">
                <button type="button" class="btn btn-default dropdown-toggle" data-toggle="dropdown" aria-expanded="false">Actions <span class="caret"></span></button>
                <ul class="dropdown-menu" role="menu">
                    <li><button type="submit" name="command" value="Delete" class="btn btn-link">Delete</button></li>
                    <li><button type="submit" name="command" value="Mark As Read" class="btn btn-link">Mark As Read</button></li>
                    <li><button type="submit" name="command" value="Mark As UnRead" class="btn btn-link">Mark As UnRead</button></li>
                </ul>
            </div>
            <div>
                <hr/>
            </div>
            <table class="table">
                <tr>
                    <th><input type="checkbox" id="selectAll" name="selectAll" /></th>
                    <th>To</th>
                    <th>Subject</th>
                    <th>Time</th>
                </tr>
                @foreach (var item in Model)
                {
                    if (item.MessageStatus == ESupervision.Models.MessageStatus.Unread)
                    { 
                        <tr>
                            <td>
                                <input type="checkbox" name="selectedSentMessages" value="@item.MessageSentID" />
                            </td>
                            <td>
                                @{
                                    foreach (var messageRecipient in item.Message.MessageRecipients)
                                    {
                                        <b>@messageRecipient.ReceiverUser.FullName</b> <br />
                                    }
                                }
                            </td>
                            <td>
                                <b>@Html.ActionLink(item.Message.Subject, "Read", new { id = item.Message.ID, sId = item.MessageSentID })</b>
                            </td>
                            <td>
                                <b>@Html.DisplayFor(modelItem => item.SentTime)</b>
                            </td>
                        </tr>
                    }
                    else
                    {
                        <tr>
                        <td>
                            <input type="checkbox" name="selectedSentMessages" value="@item.MessageSentID" />
                        </td>
                        <td>
                            @{
                                foreach (var messageRecipient in item.Message.MessageRecipients)
                                {
                                    @messageRecipient.ReceiverUser.FullName <br />
                                }
                            }
                        </td>
                        <td>
                            @Html.ActionLink(item.Message.Subject, "Read", new { id = item.Message.ID, sId = item.MessageSentID })
                        </td>
                        <td>
                            @Html.DisplayFor(modelItem => item.SentTime)
                        </td>
                    </tr>
                    }
                    
                }

            </table>
        </div>
    }
</div>
@section scripts {
    <script>
        $('#selectAll').change(function () {
            if ($(this).prop('checked')) {
                $('tbody tr td input[type="checkbox"]').each(function () {
                    $(this).prop('checked', true);
                });
            } else {
                $('tbody tr td input[type="checkbox"]').each(function () {
                    $(this).prop('checked', false);
                });
            }
        });
    </script>
}